import { Body, JsonController, Get, Post } from "routing-controllers";
import Mock, { Random } from "mockjs";
import { BaseResponse } from "../common/BaseResponse";
import { contextPath } from "../constant/CommonConstant";
@JsonController(`${contextPath}/user`)
export class UserController {
  @Get("/getInfo")
  getInfo() {
    const template = {
      user: {
        userId: "@integer(10000)",
        userName: "@cname(2,3)",
        avatar:
          "https://img2.baidu.com/it/u=4285632301,4191799154&fm=253&app=120&size=w931&n=0&f=JPEG",
        roles: ["admin"],
        permissions: ["system:admin"],
      },
    };
    return BaseResponse.success(Mock.mock(template));
  }

  @Post("/login")
  login(@Body() userRequest: any) {
    if (
      userRequest.username === "admin" &&
      userRequest.password === "12345678"
    ) {
      return BaseResponse.success({
        token: Mock.mock("@integer(10000)"),
      });
    }
    return BaseResponse.error();
  }

  @Post("/logout")
  logout() {
    return BaseResponse.success(null);
  }
}
